Skip to content

Conversation

@theotherjimmy
Copy link
Contributor

@theotherjimmy theotherjimmy commented Dec 30, 2025

cranelift requires that bitwise operations work across all data types, including floating point. The prior implementation of bitwise operations, xor in this example, would cause a panic with the message:
no rule matched for term aluop_xor

This patch adds lowerings for bitwise operations on floating point registers using the vector instructions and the vector register overlay property of the s390x register file.

Partially addresses Issue #12197

cranelift requires that bitwise operations work across all
data types, including floating point. The prior implementation
of bitwise operations, xor in this example, would cause a panic
 with the message:
    no rule matched for term aluop_xor

This patch adds lowerings for bitwise operations on floating
point registers using the vector instructions and the vector
register overlay property of the s390x register file.
@theotherjimmy theotherjimmy requested a review from a team as a code owner December 30, 2025 15:49
@theotherjimmy theotherjimmy requested review from alexcrichton and removed request for a team December 30, 2025 15:49
@github-actions github-actions bot added the cranelift Issues related to the Cranelift code generator label Dec 30, 2025
Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lowerings here look reasonable but would you mind adding a runtest (or adding s390x to an existing runtest if one exists) as well, to verify?

@theotherjimmy
Copy link
Contributor Author

Yes. I'll make sure this is part of a runtest.

@theotherjimmy
Copy link
Contributor Author

So I added a simple test to bitops:

function %test_bnot_f32(f32) -> f32 fast {
block0(v0: f32):
    v2 = bnot v0
    return v2
}

; run: %test_bnot_f32(0x1.0) == -0x1.fffffep1

which causes pulley to panic:

    ; cargo run test ./filetests/filetests/runtests/bitops.clif
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.09s
     Running `/home/jimbri01/src/rust/wasmtime/target/debug/clif-util test ./filetests/filetests/runtests/bitops.clif`

thread 'worker #1' (299483) panicked at cranelift/codegen/src/isa/pulley_shared/lower/isle.rs:207:22:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[2026-01-07T16:10:38Z ERROR cranelift_filetests::concurrent] FAIL: panicked in worker #1: called `Option::unwrap()` on a `None` value
FAIL ./filetests/filetests/runtests/bitops.clif: panicked in worker #1: called `Option::unwrap()` on a `None` value
1 tests
Error: 1 failure

So do I need to fix something in pulley to get this working?

@alexcrichton
Copy link
Member

I believe that's because Pulley doesn't implement bitwise fp ops, so you'll want to add a new *.clif runtest file which excludes pulley from the targets that are tested for that

@theotherjimmy
Copy link
Contributor Author

Is pulley missing these bitops something that we should track in Issue #12197 ?

@theotherjimmy
Copy link
Contributor Author

Looks like aarch64 has a problem with fp bitops as well.

pulley and aarch64 omitted as they currently fail this test
@theotherjimmy
Copy link
Contributor Author

I removed aarch64 from the fp-bitops test. I'm thinking this should pass now.

@alexcrichton
Copy link
Member

Thanks! It's fine I think to leave Pulley out of that issue since it's a much more constrained backend than the others, but thanks for the consideration!

@alexcrichton alexcrichton enabled auto-merge January 7, 2026 18:16
@alexcrichton alexcrichton added this pull request to the merge queue Jan 7, 2026
Merged via the queue into bytecodealliance:main with commit 7b4a3e1 Jan 7, 2026
76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants